package com.example.hoasbackend.web.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.hoasbackend.common.JsonResponse;
import com.example.hoasbackend.service.NationService;
import com.example.hoasbackend.model.domain.Nation;


/**
 *
 *  前端控制器
 *
 *
 * @author lhx
 * @since 2022-03-03
 * @version v1.0
 */
@Controller
@RequestMapping("/api/nation")
public class NationController {

    private final Logger logger = LoggerFactory.getLogger( NationController.class );

    @Autowired
    private NationService nationService;

    /**
    * 描述：根据Id 查询
    *
    */
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public JsonResponse getById(@PathVariable("id") Long id)throws Exception {
        Nation  nation =  nationService.getById(id);
        return JsonResponse.success(nation);
    }

    /**
    * 描述：根据Id删除
    *
    */
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    @ResponseBody
    public JsonResponse deleteById(@PathVariable("id") Long id) throws Exception {
        nationService.removeById(id);
        return JsonResponse.success(null);
    }


//    /**
//    * 描述：根据Id 更新
//    *
//    */
//    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
//    @ResponseBody
//    public JsonResponse updateNation(@PathVariable("id") Long  id,Nation  nation) throws Exception {
//        nation.setId(id);
//        nationService.updateById(nation);
//        return JsonResponse.success(null);
//    }


    /**
    * 描述:创建Nation
    *
    */
    @RequestMapping(value = "", method = RequestMethod.POST)
    @ResponseBody
    public JsonResponse create(Nation  nation) throws Exception {
        nationService.save(nation);
        return JsonResponse.success(null);
    }
}

